<template>
  <div>
    <div class="grid">
      <div v-for="(image, index) in tableData" :key="index" class="item">
        <img :src="image.src" :alt="image.alt" />
      </div>
    </div>
    <el-pagination v-model="currentPage" :page-sizes=pageSize  layout="sizes, prev, pager, next, total"
      :total=total @current-change="handleCurrentChange" />
  </div>
</template>

<script>
import PictureApi from '../../api/classify'
export default {
  data() {
    return {
      tableData: [],
      currentPage: 1,
      pageSize: [8],
      total: 0
    };
  },
  mounted() {
    this.getPicLists();
  },
  methods: {
    //获取图片数据 分页
    getPicLists() {
      this.tableData = []
      let that = this;
      let param = new URLSearchParams();
      
      param.append('pageNumber', that.currentPage);
      param.append('pageSize', that.pageSize);
      PictureApi.getPicList(param).then(res => {
        that.total = res.data.data.total
        that.tableData = res.data.data.records
      }).catch(function (err) {
        that.$message(err);
      })
      console.log(this.tableData) 
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
      this.getPicLists();
    },

  }
};
</script>

<style scoped>
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  grid-gap: 10px;
}

.item {
  width: 88%;
  padding-bottom: 88%;
  position: relative;
}

img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
</style>
